<?php
$username = "root";
           $password = "";
           $hostname = "localhost";
           $conn = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
           mysql_select_db("worldmusic",$conn) or die("Could not select database");
           mysql_query("SET NAMES 'UTF8'");
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $masp = $_POST['masp'];
    mysql_query("INSERT INTO comment SET ID='$masp',Name='".mysql_escape_string($_POST['name'])."',Content='".mysql_escape_string($_POST['content'])."'");
    header("location: ".$_SERVER['PHP_SELF']."?masp=$masp");
    exit;
} else 
    $masp = $_GET['masp'];


session_start();

?>
<html>
<head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
    <title>World Music</title>
    <link rel="stylesheet" type="text/css" href="style/style.css">
    <link rel="stylesheet" type="text/css" href="style/hdmenu.css">
    <link rel="stylesheet" type="text/css" href="style/loginbox.css">
    <link rel="stylesheet" type="text/css" href="style/preview.css"/>
    <link rel="stylesheet" type="text/css" href="style/wt-rotator.css"/>
    <link rel="stylesheet" type="text/css" href="style/productshow.css"/>
    <link rel="shortcut icon" href="../favicon.ico"> 
    <link rel="stylesheet" type="text/css" href="css/demo.css" />
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    <link rel="stylesheet" type="text/css" href="css/jquery.jscrollpane.css" media="all" />
    <script type="text/javascript" src="js/header.js"></script>
    <script type="text/javascript" src="script.js"></script>
    <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="js/jquery.wt-rotator.min.js"></script>
    <script type="text/javascript" src="js/preview.js"></script>    
    <script type="text/javascript" src="banner_images/swfobject.js"></script>
    
    <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
    <link href="css/fotorama.css" rel="stylesheet">
    <script src="js/fotorama.js"></script>

    <link href="css/generic-notForMcTabs.css" rel="stylesheet" type="text/css" />
    <link href="css/mctabs.css" rel="stylesheet" type="text/css" />
    <script src="js/javascript-tabs.js" type="text/javascript"></script>
</head>   

</head>
<body>
  <div id="contains">
    <div id="head">
      <div id="head_menu">
        <div class="logo">
            <a alt="World Music" title="World Music" href=".">
                <img width="85" alt="Trang chủ" src="images/logo.png">
            </a>
        </div>
        <div class="hdmenu">
          <div class="menu_header">
            <ul id="nav">
              <li><a href=".">Home</a></li>
              <li class="sub"><a href="#">Loa</a>
                <ul>
                  <li><a href="products.php?comp=Sony">Sony</a></li>
                  <li><a href="products.php?comp=Bose">Bose</a></li>
                </ul>
              </li>
              <li class="sub"><a href="#">Máy MP3</a>
                <ul>
                  <li><a href="products.php?comp=Sony">Sony</a></li>
                  <li><a href="products.php?comp=Bose">Bose</a></li>
                </ul>
              </li>
              <li><a href="#">About</a></li>
              <li><a href="#">Contacts</a></li>
            </ul>
          </div>
        </div>   
        <?php
        include 'config.php';
        if(isset($_SESSION['user']) && isset($_SESSION['lName']) && isset($_SESSION['fName']))
        {
          $username=$_SESSION['fName']." ".$_SESSION['lName']; 
        ?>
        <div class="box_login">
           <span>Xin chào:</span>
            <a class='login_txt' href=''><?php echo $username;?></a>
            <a class='login_txt' href='user/logout.php'><span>| Logout</span></a>
            <br class="clear_both">
        </div>
        <?php } else { ?>  
        <div class="box_login">                
          <a onclick="registrybox()" class="bt_register_a" href="javascript:void(0)">Đăng ký</a>
          <a onclick="loginbox()" class="bt_login_a big-link" href="javascript:void(0)">Đăng Nhập</a>
          <br class="clear_both">    
        </div>
        <?php } ?>
        <div class="search_box">
            <form autocomplete="off" name="frmSearch" id="frmSearch" method="post" enctype="multipart/form-data" action ="search.php"> 
                <input type="text" value="Tìm kiếm: Loa,Mp3" class="search_text" id="keyword" name="keyword" onfocus="if (this.value == 'Tìm kiếm: Loa,Mp3') {this.value = ''; }" onblur="if (this.value == '') { this.value = 'Tìm kiếm: Loa,Mp3';}" autocomplete="off">
                <input type="submit" class="search_btn" value="Tìm Kiếm">
            </form>
        </div>
        <br class="clear_both">
      </div>
    </div>

    <!-- Search Result -->
    <ul class="auto-complete-list" style="display: none; height: auto; top: 90px; left: 920.5px; width: 245px;">
    </ul>

    <!-- Login Box -->
    <div id="login-box" class="login">
      <p class="login_title"> Đăng nhập</p>
      <a href="" class="close"><img src="images/close.png" class="img-close" title="Close Window" alt="Close" /></a>
      <form method="POST" class="login-content" action="#">
          <label class="username">
          <span>Tên đăng nhập</span>
          <input id="username" name="username" value="" type="text" autocomplete="on" placeholder="Username">
          <p id="uNo"></p>
          </label>
          <label class="password">
          <span>Mật khẩu</span>
          <input id="password" name="password" value="" type="password" placeholder="Password">
          <p id="pNo"></p>
          </label>
          <p id="rs"></p>
          <button class="button submit-button" type="button" onclick="dangnhap()">Đăng nhập</button>
          <p>
          <a class="forgot" href="#">Quên mật khẩu?</a>
          </p>        
      </form>
    </div>

    <!-- Registry Box -->
    <div id="register-box" class="registry">
      <p class="registry_title"> Đăng ký</p>
      <a href="" class="rclose"><img src="images/close.png" class="img-close" title="Close Window" alt="Close" /></a>
      <form method="POST" class="registry-content" action="#">
          <label class="firstname">
            <span>Tên</span>
            <input id="firstname" name="firstname" value="" type="text" autocomplete="on" placeholder="Tên">
          </label>
          <label class="lastname">
            <span>Họ</span>
            <input id="lastname" name="lastname" value="" type="text" autocomplete="on" placeholder="Họ">
           </label>
          <label class="username">
            <span>Tên đăng nhập</span>
            <input id="username" name="username" value="" type="text" autocomplete="on" placeholder="Tên đăng nhập">
          </label>
          <label class="password">
            <span>Mật khẩu</span>
            <input id="password" name="password" value="" type="password" placeholder="Mật khẩu">
          </label>
          <label class="confirmpassword">
            <span>Xác nhận mật khẩu</span>
            <input id="confirm" name="confirmpassword" value="" type="password" placeholder="Xác nhận mật khẩu">
          </label>
          <label class="gender">
            <span>Bạn là </span>
            <select name="gender">
              <option value="Male" selected>Nam</option>
              <option value="Female">Nữ</option>
            </select>
          </label>
          <label class="email">
            <span>Email</span>
            <input id="email" name="email" value="" type="text" autocomplete="on" placeholder="you@local.com">
          </label>
          <label class="address">
            <span>Địa chỉ</span>
            <input id="address" name="address" value="" type="text" autocomplete="on" placeholder="Ho Chi Minh">
          </label>
          <p id="reg_error"></p>
          <button class="button submit-button" type="button" onclick="dangky()">Đăng ký</button>
          <div>
          <a class="forgot" href="#">Quên mật khẩu?</a>
          </div>        
      </form>
    </div>

    <div class="clear"></div>
    <div class="leftmid">
    <div class="left">
      <img src="images/banner1.png">
    </div>
    <div class="right2">
    <div id="body">
      <div id="comp">
        <a href="http://localhost/ass/products.php?comp=Sony">Sony</a>
        <a href="http://localhost/ass/products.php?comp=Bose">Bose</a>
        <a href="#">SamSung</a>
        <a href="#">Electronic</a>
        <a href="#">Apple</a>
        <a href="#">Yamaha</a>
        <a href="#">LG</a>
        <a href="#">Huyndai</a>
        <a href="#">Uniliver</a>
        <a href="#">Toyota</a>
        <a href="#">Posche</a>
        <a href="#">Suzuki</a>
        <a href="#">Honda</a>
        <a href="#">Inovo</a>
        <a href="#">Sanyo</a>
      </div>
      <div align="center"> 
        <div id="flashcontent">
          <script type="text/javascript"> 
            var so = new SWFObject("banner_images/banner.swf", "mymovie", "960", "220", "11"); 
            so.addParam("menu", "false"); 
            so.write("flashcontent"); 
          </script> 
        </div> 
      </div>  
      <div class="showproduct">
        <?php
          $masp=inject($_GET['masp']);
        ?>
        <div class="imageshow"> 
          <div class="fotorama" data-width="550" data-ratio="600/400" data-max-width="100%">
            <?php
            $result = mysql_query("SELECT * FROM product where pID='".$masp."'");
            while ($row = mysql_fetch_array($result)){
              $link = explode(';',$row['pPicture']);
              $dem = 0;
              while($element = each($link))
              {

                if ($dem==0){
                  $dem++;
                  continue;
                }
                echo "<img src=\"".$element["value"]."\">";
                $dem++;
              }
            }
            ?>
          </div>
        </div>
        <div class="thongsokithuat">
          <p>
             <?php
                $result = mysql_query("SELECT * FROM product where pID=".$masp."");
                if (!$result)
                  die("khong tim thay san pham");
                while ($row = mysql_fetch_array($result)){
                  echo "<h1>".$row['pName']."</h1><br><br>";
                  echo "Giá bán:    ".$row['pOriginalPrice']."<br>";
                  echo "Tình trạng:";
                  if($row['pCurrentQuantity']==0)
                    echo "Hết hàng<br>";
                  else
                    echo "Còn hàng<br>";
                  echo "<h4>Khuyến mãi:</h4>";
                  echo "<ul>";
                    echo "<li>";
                      if($row['psaleoff']!=0)
                        echo "Giảm ngay ".$row['psaleoff']."khi mua sản phẩm.";
                    echo "</li>";
                    echo "<li>";
                      echo "Tặng phiếu mua đồ trị giá 1000000đ";
                    echo "</li>";
                  echo "</ul><br><br><br>";

                }
                
                echo "<a href=\"addcart.php?item=".$masp."\"><img src='images/giohang.jpg'></a>";
            
              ?>
            
          </p>
        </div>
        <div id="demopage">
            <div class="container1">
                <ul id="tabs1" class="mctabs">
                    <li><a href="#view1"><h4>Thông số</h4></a></li>
                    <li><a href="#view2"><h4>Mô tả</h4></a></li>
                    <li><a href="#view3"><h4>Ý kiến</h4></a></li>
                </ul>
                <div class="panel-container">
                    <div id="view1">
                      <table>
                        <?php
                          $result = mysql_query("SELECT * FROM product where pID=".$masp."");
                          while ($row = mysql_fetch_array($result)){

                            $link = explode(';',$row['pSpecifications']);
                            while($element = each($link))
                            {
                              echo "<tr>";
                                echo "<td>";
                                  echo $element["value"];
                                echo "</td>";
                              echo "</tr>";
                            }
                          }
                        ?>
                      </table>
                    </div>
                    <div id="view2">
                      <?php
                        $result = mysql_query("SELECT * FROM product where pID=".$masp."");
                        while ($row = mysql_fetch_array($result)){
                          echo $row['pDescription'];
                        }
                      ?>
                    </div>
                    <div id="view3">
                      <?php
                        $comment_req = mysql_query("SELECT * FROM comment WHERE ID='$masp'");
                        $nbre_comment = mysql_num_rows($comment_req);
                      ?>

                      <b><?php echo $nbre_comment ?> Comments on this product:</b><br />
                      <?php while ($comment = mysql_fetch_array($comment_req)) {?>
                      <b><i><?php echo $comment['Name'] ?><br>
                      <?php echo $comment['Content'] ?><br /><br />
                      <?php 
                      } 
                      if (isset($_SESSION['user']))
                      {
                      ?>
                          <form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>" name="ajoutcomment">
                          <input type="hidden" name="masp" value="<?php echo $masp?>">
                          Author: 
                          <input type="text" name="name" value="<?php echo $_SESSION['user']?>">
                          Content:
                          <textarea name="content" rows="5" cols="10"></textarea>
                          <input type="submit" name="submit" value="Comment">

                      </form>
                      <?php
                      }
                      ?>
                    </div>
                </div>
            </div>
        </div>
        <div class="sanphamlienquan">
        <br>
        <h1>Sản phẩm liên quan</h1>
        
        <?php
          $result = mysql_query("SELECT * FROM product order by pSoldQuantity desc");
          
           $masp="";
 
           $dem = 1;
           while($row = mysql_fetch_array($result))
           {
               if ($dem>4)
                 break;
               $link = explode(';',$row['pPicture']);
               echo "<div class=\"prod_box\">";
               echo "<span  class='masp' style='display:none;'>" .$row['pID']. "</span>";
                     echo "<div class=\"cen_box\">";
                         echo "<div class=\"prod_name\"><a href=\"#\">".$row['pName']."</a></div>";
                           echo "<div class=\"prod_imag\"><a href=\"http://localhost/ass/prod_show.php?masp=".$row['pID']."\"><img src=\"".$link[0]."\" alt=\"Loa1\"/></a></div>";
                           echo "<div class=\"prod_price\">";
                             echo "<span class=\"reduce\">".$row['pOriginalPrice']."$</span>";
                           echo "</div>";
                       echo "</div>";
                 echo "</div>";
                 $dem++;
           }
 
         ?>
         <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> 
        </div>   
      </div>
    </div>
    <div class="footer">
      <div class="leftMfooter">
          <div class="leftfooter">
            <div class="footer-title">
              <h2> Thông tin liên lạc </h2>
            </div> 
            <div class="contentleft">
              <p class="p1title">Hotline bán hàng : </p>
              <ul>
                <li>
                  Hotline - HN :
                  <strong>098.8888.465 - 094.8888.196</strong>
                </li>
                <li>
                  Hotline - HCM :
                  <strong>098.8888.162 - 090.2121.288</strong>
                  <ul style="list-style: circle outside none;">
                    <li>669 Lê Hồng Phong - Quận 10</li>
                    <li>465 Võ Văn Tần - Quận 3</li>
                    <li>165 Nguyễn Thái Học - Quận 1</li>
                    <li>45 Trần Quang Khải - Quận 1</li>
                  </ul>
                </li>
              </ul>
              <p class="p2title"> Chăm sóc khách hàng :</p>
              <ul>
                <li>HN: 094.8888.162</li>
                <li>HCM: 098.8888.465</li>
                <li>
                  <a href="mailto:cskh@cellphones.com.vn">Mail: SoundWorld@music.com.vn</a>
                </li>
              </ul>   
            </div>
          </div>
          <div class="midfooter">
            <div class="footer-title">
              <h2> Thông tin hỗ trợ </h2>
            </div> 
            <div class="contentmid">
              <div class="ulleft">
                <ul>
                  <li>
                    <a href="#">Giới thiệu</a>
                  </li>
                  <li>
                    <a href="#">Bảo hành</a>
                  </li>
                  <li>
                    <a href="#">Mua hàng</a>
                  </li>
                  <li>
                    <a href="#">Chuyển hàng</a>
                  </li>
                </ul>
              </div>
              <div class="ulright">
                <ul>
                  <li>
                    <a href="http://cellphones.com.vn/deals-phu-kien-hn">Deals phụ kiện</a>
                  </li>
                  <li>
                    <a href="http://cellphones.com.vn/smember/dang-ki-ban-may-cu">Bán - Đổi máy cũ</a>
                  </li>
                  <li>
                    <a href="http://cellphones.com.vn/dich-vu-khach-hang-doanh-nghiep">Khách hàng doanh nghiệp</a>
                  </li>
                  <li>
                    <a href="http://cellphones.com.vn/smember/dat-hang-tai-cellphones">Đặt mua hàng không có sẵn</a>
                  </li>
                </ul> 
              </div>
              <div class="box-phone">
                <span class="phone">
                  Tổng đài HN: 19006112
                  <br>
                </span>
                <ul class="support-number">
                  <li>Ấn số 1 để được tư vấn bán hàng online</li>
                  <li>Ấn số 2 để gặp bộ phận bảo hành - sửa chữa DV</li>
                  <li>Ấn số 3 để được gặp bộ phận kỹ thuật</li>
                  <li>Ấn số 4 để gặp cửa hàng 117 Thái Hà</li>
                  <li>Ấn số 5 để gặp cửa hàng 19 Thái Hà</li>
                  <li>Ấn số 6 để gặp cửa hàng 21A Hàng Bài</li>
                  <li>Ấn số 7 để gặp cửa hàng 306 Cầu Giấy</li>
                </ul>
              </div>
            </div>
          </div>
      </div>
      <div class="rightfooter">
        <div class="footer-title">
              <h2> Hệ thống cửa hàng </h2>
        </div> 
        <div class="contentright">
          <ul class="showroom">
            <li>
              <a href="#">306 Cầu Giấy, Q. Cầu Giấy, Hà Nội</a>
            </li>
            <li>
              <a href="#">117 Thái Hà, Đống Đa, Hà Nội</a>
            </li>
            <li>
              <a href="#">19 Thái Hà, Đống Đa, Hà Nội</a>
            </li>
            <li>
              <a href="https://www.google.com/maps/place/21+H%C3%A0ng+B%C3%A0i,+Ho%C3%A0n+Ki%E1%BA%BFm/@21.0237587,105.852853,17z/data=!3m1!4b1!4m2!3m1!1s0x3135abecb225927d:0xe70e66e73ce62582">21A Hàng Bài, Hoàn Kiếm, Hà Nội</a>
            </li>
            <li>
              <a href="#">713 Nguyễn Trãi, Q5, HCM</a>
            </li>
            <li>
              <a href="#">45 Trần Quang Khải, Q1, HCM</a>
            </li>
            <li>
              <a href="#">465 Võ Văn Tần, Q3, HCM</a>
            </li>
            <li>
              <a href="#">165 Nguyễn Thái Học, Q1, HCM </a>
            </li>
            <li>
              <a href="#">669 Lê Hồng Phong, Q10, HCM</a>
            </li>
            <li class="last">( vui lòng bấm để xem bản đồ)</li>
          </ul>
          <p>Giờ mở cửa: 8h30 - 21h30 tất cả các ngày trong tuần</p>
        </div>
      </div>
    </div>
    </div>
    </div>
    <div class="right">
      <img src="images/banner2.png">
    </div>
  </div>
</body>
<script>







$(document).ready(function(){ 

  (function($){
    $('.right').advScroll({
      easing:'easeOutBack',
      timer:1000
    });
  })(jQuery);

  (function($){
    $('.left').advScroll({
      easing:'easeOutBack',
      timer:1000
    });
  })(jQuery);
});


</script>
</html>